Dart StringBuffer operator ==
Syntax & Examples
StringBuffer.operator == operator
The `operator ==` in Dart is the equality operator, used to check if two objects are equal.
Syntax of StringBuffer.operator ==
The syntax of StringBuffer.operator == operator is:
operator ==(dynamic other) → boolThis operator == operator of StringBuffer the equality operator.
Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
other | required | the object to compare for equality |
✐ Examples
1 Check equality of two strings
In this example,
We create two strings `str1` and `str2` with the same value 'Hello'. We use the `==` operator to check if they are equal.
Dart Program
void main() {
String str1 = 'Hello';
String str2 = 'Hello';
bool isEqual = (str1 == str2);
print('Is str1 equal to str2: $isEqual');
}Output
Is str1 equal to str2: true
2 Check equality of two integers
In this example,
We create two integers `num1` and `num2` with the same value 42. We use the `==` operator to check if they are equal.
Dart Program
void main() {
int num1 = 42;
int num2 = 42;
bool isEqual = (num1 == num2);
print('Is num1 equal to num2: $isEqual');
}Output
Is num1 equal to num2: true
3 Check equality of two lists
In this example,
We create two lists `list1` and `list2` with the same elements. We use the `==` operator to check if they are equal.
Dart Program
void main() {
List<int> list1 = [1, 2, 3];
List<int> list2 = [1, 2, 3];
bool isEqual = (list1 == list2);
print('Is list1 equal to list2: $isEqual');
}Output
Is list1 equal to list2: true
Summary
In this Dart tutorial, we learned about operator == operator of StringBuffer: the syntax and few working examples with output and detailed explanation for each example.